package Group9.TodoManager.Actions;

import Group9.TodoManager.Data.Interface.ITableModel;
import Group9.TodoManager.Data.Task;
import Group9.TodoManager.DataStore.Repository;
import Group9.TodoManager.Settings;
import java.awt.event.ActionEvent;
import javax.swing.Action;
import javax.swing.ImageIcon;

/**
 * This action is meant for editing a selected task.
 * @author Rupesh
 * @author volkan cambazoglu
 */
public class EditAction<T> extends TodoManagerAction {
    private ITableModel<T> tableModel;
    private Repository<T> repository;

    /**
     * Constructor. Creates an instance of EditAction class.
     * It will be used when editing a task object.
     * @param name name of the action
     * @param icon icon of the action
     * @param toolTipText tool tip of the action
     * @param mnemonic mnemonic of the action
     * @param table table model
     * @param repo repository
     */
    public EditAction(String name,ImageIcon icon, String toolTipText, 
             int mnemonic, ITableModel<T> table, Repository<T> repo){

        super(name, icon);
        putValue(Action.SHORT_DESCRIPTION, toolTipText);
        putValue(Action.MNEMONIC_KEY, mnemonic);
        tableModel = table;
        repository = repo;
    }

    /**
     * When this method will be executed, it will show the UI inside 
     * a dialog frame. The UI will be presented with fields that are
     * filled with information about the task.
     * @param e event
     */
    @Override
    public void actionPerformed(ActionEvent e) {
    	Task task = (Task) tableModel.getRowObject(tableModel.getSelectedRowIndex());
    	Settings.showDialog(Settings.getCreateTaskUI(task));
    }
}
